# encoding: utf-8
class ProcessorsController < ApplicationController
  before_filter :is_member_of_project?
  before_filter :get_project
  before_filter :get_workpackage
  before_filter :get_task

  def new
    @processor = Processor.new

    respond_to do |format|
      format.html
      format.xml { render :xml => @processor }
    end
  end

  def create
    @processor = Processor.new(params[:processor])
    @processor.task_id = params[:task_id]

    respond_to do |format|
      if @processor.save
        flash[:notice] = t :processor_add_success, :scope => [:flash, :notice]
        format.html { redirect_to(project_workpackage_task_path(params[:project_id], params[:workpackage_id], @task)) }
        format.xml { render :xml => @task, :status => :created, :location => @task }
      else
        format.html { render :action => "new" }
        format.xml { render :xml => @processor.errors, :status => :unprocessable_entity }
      end
    end
  end

  def destroy
    @processor = Processor.find(params[:id])
    @processor.destroy
    flash[:notice] = t :processor_delete_success, :scope => [:flash, :notice]
    redirect_to(project_workpackage_task_path(params[:project_id], params[:workpackage_id], @task))
  end

end